package com.wft.面试题;

import java.util.TreeSet;

public class 父类子类比较 {
    public static void main(String[] args) {
        TreeSet treeSet = new TreeSet();
        treeSet.add(new Parent(3));
        treeSet.add(new Parent(4));
        treeSet.add(new Child());
        System.out.println(treeSet.size());
    }
}

class Parent implements Comparable {
    private int age = 0;

    public Parent(int age) {
        this.age = age;
    }

    public int compareTo(Object o) {
        System.out.println("method of parent");
        Parent o1 = (Parent) o;
        return age > o1.age ? 1 : age < o1.age ? -1 : 0;
    }
}

class Child extends Parent{

    public Child() {
        super(3);
    }

    public int compareTo(Object o) {
        System.out.println("method of child");
        Child o1 = (Child) o;
        return 1;
    }

}
